home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / atibgi.zip / VGATEST.C < prev    next >
Text File  |  1990-05-26  |  3KB  |  120 lines

  1. /* A simple demo program to show the use of the bgi driver in C              */
  2. /* Copyright (C)1990 by Peter F. Jones. ALL RIGHTS RESERVED                  */
  3. /* Note: you must link it to ativw256.obj which has the autodetect function. */
  4.  
  5.  
  6.  
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <dos.h>
  10. #include <math.h>
  11. #include <graphics.h>
  12. #include "ativw256.h"
  13.  
  14.  
  15.  
  16. void triangle(int x1, int y1,  int x2,  int y2,  int x3, int y3)
  17. {
  18.  int tri[8];
  19.  
  20.    tri[0] = x1;
  21.    tri[1] = y1;
  22.    tri[2] = x2;
  23.    tri[3] = y2;
  24.    tri[4] = x3;
  25.    tri[5] = y3;
  26.    tri[6] = x1;
  27.    tri[7] = y1;
  28.  
  29.    fillpoly(4,tri);
  30.  
  31. };
  32.  
  33.  
  34. main()
  35. {
  36.  
  37. int driver,mode;
  38. int counter;
  39. int xc,yc,x1,y1,x2,y2;
  40. float scale,angle_factor;
  41. int r,g,b;
  42. float angle_offset,angle_offset_r,angle_offset_g,angle_offset_b;
  43. float angle;
  44.  
  45. char far *driver_name;
  46.  
  47.  
  48. driver = installuserdriver("ativw256",detect_ATI_VGA_Wonder);
  49. if (grOk !=graphresult())
  50.    {
  51.      printf("Error in installing ATI VGA Wonder Driver\n");
  52.      exit(1);
  53.    };
  54.  
  55. driver = DETECT;
  56. initgraph(&driver,&mode,"");
  57. if (grOk !=graphresult())
  58.    {
  59.      printf("Error in init\n");
  60.      exit(1);
  61.    };
  62.  
  63.    xc = getmaxx()/2;
  64.    yc = getmaxy()/3;
  65.  
  66.  
  67.   driver_name = getdrivername();
  68.   xc = xc - (  textwidth("Driver Name: ")+textwidth(driver_name) )/2;
  69.   setcolor(WHITE);
  70.   outtextxy(xc,yc,"Driver Name: ");
  71.   xc = xc + textwidth("Driver Name: ");
  72.   outtextxy(xc,yc,driver_name);
  73.  
  74.  
  75.   xc = getmaxx()/2;
  76.   yc = getmaxy()/2;
  77.   scale = getmaxy()/2;
  78.   angle_factor = 2*3.14159/(float)(1+getmaxcolor());
  79.   for(counter=0;counter<=getmaxcolor();counter++)
  80.      {
  81.        setcolor(counter);
  82.        setfillstyle(SOLID_FILL,counter);
  83.        x1 = xc + (int) (scale * cos( angle_factor * (double)counter));
  84.        y1 = yc + (int) (scale * sin( angle_factor * (double)counter));
  85.  
  86.        x2 = xc + (int) (scale * cos( angle_factor * (double)(counter+1)));
  87.        y2 = yc + (int) (scale * sin( angle_factor * (double)(counter+1)));
  88.        triangle(xc,yc,x1,y1,x2,y2);
  89.      }
  90.  
  91.  
  92. angle_offset = 0.0;
  93. while(!kbhit())
  94.   {
  95.  
  96.   angle_offset_r  =   angle_offset;
  97.   angle_offset_g  =   angle_offset +     2.0*3.14159/3.0;
  98.   angle_offset_b  =   angle_offset + 2.0*2.0*3.14159/3.0;
  99.  
  100.   for(counter=0;counter<=getmaxcolor();counter++)
  101.      {
  102.        angle = angle_factor * (double)counter;
  103.        r  =   (int) ((63.0/2.0) * (1.0+ cos(angle_offset_r + angle)));
  104.        g  =   (int) ((63.0/2.0) * (1.0+ cos(angle_offset_g + angle)));
  105.        b  =   (int) ((63.0/2.0) * (1.0+ cos(angle_offset_b + angle)));
  106.        setrgbpalette(counter,r,g,b);
  107.      }
  108.  
  109. angle_offset = angle_offset + 0.2;
  110.  
  111.   };
  112.  
  113.  
  114.  
  115.  
  116. getch();
  117. closegraph();
  118. };
  119.  
  120.